package org.comet.auxiliary.client.swing;

import org.comet.auxiliary.common.swing.NotEditableTable;
import org.comet.auxiliary.common.util.StringUtil;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class BodyFrame  extends JDialog implements ActionListener {
    public List<String> titleList = new ArrayList<>();
    private String title;
    private JTextField jTextField;
    private JTextField jTextField1;
    private JTextField jTextField2;
    private JTextField jTextField3;
    private JTextField jTextField4;
    private JTextField jTextField5;
    private JTextField jTextField6;
    private  JLabel bt;
    private  JLabel bt1;
    private  JLabel bt2;
    private  JLabel bt3;
    private  JLabel bt4;
    private  JLabel bt5;
    private  JLabel bt6;





    @Override
    public void actionPerformed(ActionEvent e) {
        String actionCommand = e.getActionCommand();
        if("save".equals(actionCommand)){
            String tl= jTextField.getText();
            String tl1 = jTextField1.getText();
            String tl2 = jTextField2.getText();
            String tl3 = jTextField3.getText();
            String tl4 = jTextField4.getText();
            String tl5 = jTextField5.getText();
            String tl6 = jTextField6.getText();
            setList(tl);
            setList(tl1);
            setList(tl2);
            setList(tl3);
            setList(tl4);
            setList(tl5);
            setList(tl6);
            setVisible(false);
        }
    }



    public void setList(String val){
        if(!StringUtil.isBlank(val)){
            titleList.add(val);
        }
    }

    public BodyFrame(Frame owner, String title, int width, int height){
        super(owner, true);
        this.title = title;
        setBounds(700, 300, width, height);
    }



    public void openFriendList(List<String> titles) {
        setTitle("设置红包标题(可选中对象后 Ctrl+C 复制行数据, 即可获取 ID 信息)");
        setLayout(new GridLayout(1, 2, 2, 1));
         bt = new JLabel("标题");
         jTextField = new JTextField(15);
         bt1 = new JLabel("标题1");
         jTextField1 = new JTextField(15);
         bt2 = new JLabel("标题2");
         jTextField2 = new JTextField(15);
         bt3 = new JLabel("标题3");
         jTextField3 = new JTextField(15);
         bt4 = new JLabel("标题4");
         jTextField4 = new JTextField(15);
         bt5 = new JLabel("标题5");
         jTextField5 = new JTextField(15);
         bt6 = new JLabel("标题6");
         jTextField6 = new JTextField(15);
        init(titles);
        JButton saveBtn =  new JButton("保存");
        saveBtn.setActionCommand("save");
        saveBtn.addActionListener(this);
        saveBtn.setEnabled(true);
        JPanel jPanel = new JPanel();
        jPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
        jPanel.add(bt);
        jPanel.add(jTextField);
        jPanel.add(bt1);
        jPanel.add(jTextField1);
        jPanel.add(bt2);
        jPanel.add(jTextField2);
        jPanel.add(bt3);
        jPanel.add(jTextField3);
        jPanel.add(bt4);
        jPanel.add(jTextField4);
        jPanel.add(bt5);
        jPanel.add(jTextField5);
        jPanel.add(bt6);
        jPanel.add(jTextField6);
        jPanel.add(saveBtn);
        Container container = getContentPane();
        container.add(jPanel);
        setVisible(true);



    }

    private void init(List<String> titles) {
        if(titles.size()==1){
            jTextField.setText(titles.get(0));
        }
        if(titles.size()==2){
            jTextField.setText(titles.get(0));
            jTextField1.setText(titles.get(1));
        }
        if(titles.size()==3){
            jTextField.setText(titles.get(0));
            jTextField1.setText(titles.get(1));
            jTextField2.setText(titles.get(2));
        }
        if(titles.size()==4){
            jTextField.setText(titles.get(0));
            jTextField1.setText(titles.get(1));
            jTextField2.setText(titles.get(2));
            jTextField3.setText(titles.get(3));
        }
        if(titles.size()==5){
            jTextField.setText(titles.get(0));
            jTextField1.setText(titles.get(1));
            jTextField2.setText(titles.get(2));
            jTextField3.setText(titles.get(3));
            jTextField4.setText(titles.get(4));

        }
        if(titles.size()==6){
            jTextField.setText(titles.get(0));
            jTextField1.setText(titles.get(1));
            jTextField2.setText(titles.get(2));
            jTextField3.setText(titles.get(3));
            jTextField4.setText(titles.get(4));
            jTextField5.setText(titles.get(5));

        }
        if(titles.size()==7){
            jTextField.setText(titles.get(0));
            jTextField1.setText(titles.get(1));
            jTextField2.setText(titles.get(2));
            jTextField3.setText(titles.get(3));
            jTextField4.setText(titles.get(4));
            jTextField5.setText(titles.get(5));
            jTextField6.setText(titles.get(6));
        }
    }


}
